module.exports = function(grunt) {
	var pkg = grunt.file.readJSON("package.json");
	grunt.initConfig({
		config: {
            "name": "xiapshuxiong-pc",
            "version": "0.0.1",
            "author": "HuangJieHai",
            "srcPath": "src",
            "buildPath": "dist",
            "compatibility":"ie7",
            "banner": '/*<%=config.name%> v<%=config.version%>:<%=grunt.template.today("yyyy-mm-dd,h:MM:ss TT")%>*/\n'
        },
		less : {
			development : {
				options: {
					// paths: ["src/css"],
					// ieCompat : true,
					// banner: '<%=config.banner%>'
				},
				files: [{
					expand : true,
					cwd : "src/less/",
					src : "**/*.less",
					dest : "dist/css",
					ext : '.css',
					filter : function(filepath){return filepath.indexOf('base') !== 9 ;}
				}]
			},

			production : {
				options : {
					// paths: ["src/css"],
					// ieCompat : true,
					banner: '<%=config.banner%>',
					compress : true
				},
				files: [{
					expand : true,
					cwd : "src/less/",
					src : "**/*.less",
					dest : "dist/css",
					ext : '.css',
					filter : function(filepath){return filepath.indexOf('base') !== 9 ;}
				}]
			}
		},
		copy : {
			options:{
				banner: '<%=config.banner%>'
			},
			target : {
				expand: true,
				cwd: 'src/js/',
				src: ['**/*.js'],
				dest: 'dist/js',
				// ext :".js"
			}
		},
		uglify : {
			target : {
				options : {
					// sourceMap : true,
					banner: '<%=config.banner%>'
				},
				files : [{
					expand : true,
					cwd : "src/js/",
					src : "**/*.js",
					dest :  "dist/js",
					// ext : ".js",
					filter : "isFile"
				}]
			}
		},
		jshint : {
			files : {
				src : ['src/js/**/*.js','!src/js/jquery-1.11.3.js']
			},
			options : {
				jshintrc : true,

			}
		},
		watch: {
			scripts: {
				files: ['src/js/**/*.js'],
				tasks : ['jshint','copy']
			},
			stylesheets : {
				files : ['src/less/**/*.less'],
				tasks : ['less:development']
			},
			livereload: {
		      // Here we watch the files the sass task will compile to 
		      // These files are sent to the live reload server after sass compiles to them 
		      options: { livereload: true },
		      files: ['../../mall_www/themes/xiaoshuxiong/**/*', 'dist/**/*', 'src/**/*'],
		    }
		}
	});

	var tasks = pkg.devDependencies;

	for(var task in tasks){
		if(tasks.hasOwnProperty(task) && /grunt-*/.test(task)){
			grunt.loadNpmTasks(task);
		}
	}

	grunt.registerTask("default", "build and watch", function(){
		grunt.task.run('build');
		grunt.task.run(['watch']);
	});
	grunt.registerTask('build', ['less:development', 'jshint', 'copy']);
	grunt.registerTask("publish", ['less:production', 'jshint', 'uglify']);
};